const Entity = require('../../shared/entity/Entity')
const R = require('ramda')
const Menu = require('../menu/menu')
const MenuType = require('../menu/MenuType')
const { omitAuditFieldsAnd } = require('../../app/helper')

const getMenuListByType = (fn, type, list) =>
  R.compose(fn, R.filter(R.compose(R.equals(type), R.prop('type'))))(list)

const descriptor = {
  name: { required: true, message: '系统名称不能为空' },
  code: { required: true, message: '系统编码不能为空' },
}

class System extends Entity {
  name
  code
  description
  url
  icon
  menuList = []
  constructor(data) {
    super(descriptor, data)
    this.init(data)
  }
  hasMenu() {
    return this.menuList && this.menuList.length > 0
  }

  getMenuListAndButtonList() {
    return Menu.listGroupByType(this.menuList)
    // return {
    //   menuList: getMenuListByType(
    //     Menu.menuListToTree,
    //     MenuType.MENU,
    //     this.menuList
    //   ),
    //   buttonList: getMenuListByType(
    //     R.compose(R.identity, R.map(omitAuditFieldsAnd([]))),
    //     MenuType.BUTTON,
    //     this.menuList
    //   ),
    //   otherList: getMenuListByType(R.identity, MenuType.OTHER, this.menuList),
    // }
  }

  static create(data) {
    return new System(data)
  }
}

module.exports = System
